﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using SuperFind.Lib.Data;

namespace SuperFind.Lib.Core
{
    public class Settings
    {
        public void Save(List<string> locations)
        {
            StringBuilder query = new StringBuilder();
            //query.Append("DELETE * FROM FOLDERLIST;");

            OleDbUtility.TryExecuteNonQuery("DELETE * FROM FOLDERLIST");
            foreach (string location in locations)
            {
                //query.Append(String.Format("INSERT INTO {0} (PATH) VALUES('{1}')", "FOLDERLIST", location));
                //if(locations.IndexOf(location)<locations.Count-1)
                //    query.Append(";");


                OleDbUtility.TryExecuteNonQuery(String.Format("INSERT INTO {0} (PATH) VALUES('{1}')", "FOLDERLIST", location));
            }
            //OleDbUtility.TryExecuteNonQuery(query.ToString());
        }
        public List<string> LoadLocations()
        {
            List<string> locations = new List<string>();
            DataTable table = OleDbUtility.TryExecuteDataTable("SELECT PATH FROM FOLDERLIST");
            if (table != null && table.Rows.Count>0)
            {
                foreach (DataRow row in table.Rows)
                {
                    locations.Add(row["PATH"] as string);
                }
            }
            else
                locations = null;
            return locations;
        }
    }

}
